import logging

import requests

from config import base_url


class IhrmApi:

    #封装登录接口，传入数据为登录数据user
    login_url=url = base_url + "/api/sys/login"
    put_url=base_url + f"/api/sys/user/1063705989926227968"
    @classmethod
    def login(cls,user):
        res=requests.post(url=cls.login_url,json=user)
        return res


    #封装获取token方法，返回token
    @classmethod
    def get_token(cls):
        url = base_url + "/api/sys/login"
        user={"mobile":"13800000004",
              "password":"123456"}
        res=requests.post(url=url,json=user)
        token="Bearer "+res.json().get("data")

        return token

    # 封装查看员工列表
    @classmethod
    def userlist(cls):
        url=base_url + "/api/sys/user?page=1&size=10"

        head={"Authorization":IhrmApi.get_token()}
        res=requests.get(url=url,headers=head)
        return (res.json())


    #封装修改员工方法
    @classmethod
    def put_user(cls,userdata):
        print(cls.userlist())
        head = {"Authorization": IhrmApi.get_token()}
        res=requests.put(url=cls.put_url,json=userdata,headers=head)
        logging.info(cls.userlist())
        return (res)

